package Hot100.LinkNode;

import java.util.HashMap;
import java.util.Map;

public class copyRandomList {
    public static void main(String[] args) {

    }
    Map<Node,Node> cacheheadNode = new HashMap<Node, Node>() ;
    public Node copyRandomList(Node head) {
        if(head == null){
            return null;
        }
        if(!cacheheadNode.containsKey(head)){
            Node headNew = new Node(head.val);
            cacheheadNode.put(head,headNew);
            headNew.next = copyRandomList(head.next);
            headNew.random = copyRandomList(head.random);
        }
        return cacheheadNode.get(head);
    }
}
